<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- 兼容性 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>计划编制-关键节点计划列表</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
            background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div class="title-list mb-20"><span class="title-listbg"></span><span>项目主项计划</span></div>
<div id="qForm"  class="mini-toolbar1" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <div class="mb-20">
                    <span class="search-title search-ml20">项目名称</span><select id="itemId" name="itemId" class="mini-combobox w200" ajaxType="post" url="/item/list" emptyText="全部" showNullItem="true" nullItemText="全部" textField="name" valueField="id"></select>
                    <span class="search-title search-ml60">节点名称</span><input id = "nodeNames" name="nodeName" class="mini-textbox search-200px">
                    <span class="search-title search-ml60">选择年月</span><div id="yearItem"></div>
                    <a class="add-botton search-ml60" onclick="list.search()">查询</a>
                    <a class="resetting-btn search-ml20" onclick="list.reset()">重置</a>
                </div>
            </td>
        </tr>
    </table>
</div>
<div class="container">
    <!--<div class="title-list mb-20"><span>我的计划列表</span></div>-->
    <div class="mini-clearfix mb-10">
        <div class="mini-col-6 mini-col-sm-3"><!-- 
            <a class="plan-btn mR-20"  onclick="list.addOrEdit('new')"><span class="add-bg"></span>新增</a> -->
            <a class="stamp-export mR-20"  onclick="list.print()"><span class="stamp-bg"></span><span class="span-line">打印</span></a>
            <a class="bill-export mR-20"  onclick="list.exportExcel()"><span class="bill-bg"></span><span class="span-line">导出</span></a>
        </div>
    </div>
</div>
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"  url="/mainPlanNodeExecution/listByPage" allowResize="true" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id" multiSelect="false" showEmptyText="true" emptyText="暂无数据" alwaysShowEmptyText="true">

        <div property="columns">
            <!--<div type="checkcolumn" headerAlign="center" align="center"></div>-->
            <div type="indexcolumn" width="35" headerAlign="center" align="center">编号</div>
            <div field="planName" width="120" headerAlign="center" allowSort="false">计划名称</div>
            <div field="businessName" width="120" headerAlign="center" align="center" allowSort="false">业务板块</div>
            <!--<div field="planTypeName" width="120" headerAlign="center" allowSort="false">计划类型</div>-->
            <div field="nodeName" width="120" headerAlign="center" allowSort="false">节点名称</div>
            <div field="nodePropertyName" width="120" headerAlign="center" align="center" allowSort="false">节点性质</div>
            <div field="completeStandard" width="120" headerAlign="center" allowSort="false">完成标准</div>
            <div field="state" width="120" headerAlign="center" align="center" allowSort="false" renderer="list.onGenderRenderer">状态</div>
            <div field="rate" width="120" headerAlign="center" align="center" allowSort="false">进度</div>
            <div field="beginDate" width="200" headerAlign="center" align="center" allowSort="false">计划起止时间</div>
            <div field="postName" width="120" headerAlign="center" align="center" allowSort="false">负责人</div>
            <!--<div field="postId" width="120" headerAlign="center" align="center" allowSort="false">负责人</div>
        <div field="postId" width="120" headerAlign="center" align="center" allowSort="false">调整类型</div>-->
            <!--<div field="remark" width="120" headerAlign="center" align="center" allowSort="false">备注</div>-->
            <!--<div field="sendTime" width="120" headerAlign="center" align="center" allowSort="false">成果确认状态</div>-->
            <div name="action" width="240" headerAlign="center" align="center">操作</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //1未开始、2进行中 、3、有风险4、失控、5、已完成 6、延期完成
    var Genders = [{ id: 1, text: '未开始' }, { id: 2, text: '进行中'},{ id: 3, text: '有风险'}, { id: 4, text: '失控'},{ id: 5, text: '已完成'}, { id: 6, text: '延期完成'}, { id: 7, text: '逾期'}];

    var list = {
        //页面初始化
        init: function() {
            mini.parse();
            common.changeYears();
            var now = new Date();
            var time = now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1);
            mini.get("datagrid1").load({"yearMonth": time});
            mini.get("datagrid1").on("drawcell", function (e) {
                var column = e.column;
                if (column.name == "action") {
                    e.cellHtml = '<a class="check-botton" href="javascript:list.view()">填报记录</a>';
                }
                if(column.field=="beginDate"){
                    var dateText = "";
                    if(e.row.beginDate&&e.row.endDate){
                        dateText="至"
                    }
                    e.cellHtml = e.row.beginDate.substring(0,10)+dateText+e.row.endDate.substring(0,10);
                }
                if(column.field=="rate"){
                    e.cellHtml = e.row.rate+'%';
                }
                if(column.field=="state"){
                	if(e.row.state=="8"){
                        e.cellHtml = '<span>节点暂停</span>';
                    }else if(e.row.state=="9"){
                        e.cellHtml = '<span>节点取消</span>';
                    }else{
                    	if(e.row.riskState=="1"){
                    		if(e.row.state=="7"){
                                e.cellHtml = '<span class="span-orange">逾期</span>';
                            }else{
                                e.cellHtml = '<span class="span-yellow">有风险</span>';
                            }
                    	}else if(e.row.riskState=="2"){
                            e.cellHtml = '<span class="span-red">失控</span>';
                    	}else{
                    		if(e.row.state=="1"){
                                e.cellHtml = '<span>未开始</span>';
                            }else if(e.row.state=="2"){
                                e.cellHtml = '<span class="span-green">进行中</span>';
                            }else if(e.row.state=="5"){
                                e.cellHtml = '<span>已完成</span>';
                            }else if(e.row.state=="6"){
                                e.cellHtml = '<span>延期完成</span>';
                            }else if(e.row.state=="7"){
                                e.cellHtml = '<span class="span-orange">逾期</span>';
                            }
                    	}
                    }
                }
            })
        },
        onGenderRenderer: function (e) {
            for (var i = 0, l = Genders.length; i < l; i++) {
                var g = Genders[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        },
        //    新增或编辑
        addOrEdit: function (opt) {
            mini.open({
                url: "/program/monthlyPlan/new.html",
                title: (opt=="edit"?"编辑":"新增")+"计划申请", width: 1100, height: 700,
                onload: function () {
                    if(opt=="edit"){
                        var row = mini.get("datagrid1").getSelected();
                        var data = {"id": row.id,"state":opt};
                    }else{
                        var data = {"state":opt};
                    }
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    mini.get("datagrid1").reload();
                }
            });
        },
        //    填报记录
        view: function(){
            var row = mini.get("datagrid1").getSelected();
            if (row) {
                mini.open({
                    url: "/program/monthlyPlan/recordList.html",
                    title: "填报记录", width: 1100, height: 700,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {"id": row.id};
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        mini.get("datagrid1").reload();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        },
        //    查询
        search: function () {
            var years = mini.get("year").getValue();
            var mouths = mini.get("month").getValue();
            var allYear = years+'-'+mouths;
            var data = {
                "itemId": mini.get("itemId").getValue(),
                "nodeName": mini.get("nodeNames").getValue(),
                "yearMonth": allYear
            };
            mini.get("datagrid1").load(data);
        },
        //重置
        reset:function(){
            mini.get("year").setValue(new Date().getFullYear());
            var years = mini.get("year").getValue();
            var endMonth = new Date().getMonth()+1;
            mini.get("month").setValue(endMonth);
            mini.get("itemId").setValue("");
            mini.get("nodeNames").setValue("");
            var now = new Date();
            var time = now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1);
            mini.get("datagrid1").load({"yearMonth": time});
        },
        //    删除
        remove: function () {
            var row = mini.get("datagrid1").getSelected();
            if (row) {
                mini.confirm("确定删除选中记录？","确定",function (action) {
                    if(action=="ok"){
                        $.ajax({
                            url: "/messageRemind/del",
                            type : "post",
                            data:{"id":row.id},
                            success: function (text) {
                                if (text.state) {
                                    mini.get("datagrid1").reload();
                                } else {
                                    mini.showMessageBox({
                                        showModal: false,
                                        width: 250,
                                        title: "提示",
                                        iconCls: "mini-messagebox-warning",
                                        message: text.message,
                                    });

                                }
                            }
                        });
                    }
                });
            } else {
                alert("请选中一条记录");
            }
        },
        //打印
        print:function () {
            mini.open({
                url: "/program/mainItem/print.html",
                title: "关键节点计划",
                width: $(window).width(),
                height: $(window).height(),
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var years = mini.get("year").getValue();
                    var mouths = mini.get("month").getValue();
                    var allYear = years+'-'+mouths;
                    var data = {
                        "pageIndex": 0,
                        "pageSize":20,
                        "itemId": mini.get("itemId").getValue(),
                        "nodeName": mini.get("nodeNames").getValue(),
                        "yearMonth": allYear
                    };
                    iframe.contentWindow.print.SetData(data);
                },
                ondestroy: function (action) {
                    mini.get("datagrid1").reload();
                }
            });
        },//导出
        exportExcel:function () {
       	 if(mini.get("datagrid1").getTotalCount()>0) {
            var years = mini.get("year").getValue();
            var mouths = mini.get("month").getValue();
            var allYear = years+'-'+mouths;
            var data = {
                "itemId": mini.get("itemId").getValue(),
                "nodeName": mini.get("nodeNames").getValue(),
                "yearMonth": allYear,
                "pageIndex": 0,
                "pageSize":500
            };
            var params = $.param(data);
        	
			//序列化参数  
		     var url = "/mainPlanNodeExecution/exportExcel?"+params; 
			//导出请求			     
		   $('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove();
       	 }else{
               mini.alert("数据为空,不能导出");
      	 }
        }
		     
		
    };
    list.init();
</script>
</body>
</html>